<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>字符串加密</title>
</head>

<body>
    <input type="text" />
    <input type="button" value="加密">
    <input type="button" value="解密">
    <div id="txt">加密文字显示在这里~</div>
    <script type="text/javascript">
        var aIpt = document.getElementsByTagName('input');
        var oDiv = document.getElementById('txt');
        aIpt[1].onclick = function () {
            var txtVal = aIpt[0].value;
            var str = "";
            console.log(txtVal);
            for (var i = 0; i < txtVal.length; i++) {
                str += String.fromCharCode(txtVal.charCodeAt(i) - 100);
            }
            oDiv.innerHTML = str;
        }
        aIpt[2].onclick = function () {
            var txtVal = oDiv.innerHTML;
            var str = "";
            console.log(txtVal);
            for (var i = 0; i < txtVal.length; i++) {
                str += String.fromCharCode(txtVal.charCodeAt(i) + 100);
            }
            oDiv.innerHTML = str;
        }
    </script>
</body>

</html>